package com.help10000.rms.common

import android.content.Context
import android.content.Intent
import com.amir.common.beans.PushDataEntity
import com.amir.common.utils.ToastUtil
import com.help10000.rms.config.globalData
import com.help10000.rms.ui.activitys.MainActivity
import com.help10000.rms.ui.activitys.OrderActivity
import com.help10000.rms.ui.activitys.TimeOutOrderActivity
import com.help10000.rms.ui.activitys.logins.LoginActivity
import com.help10000.rms.ui.activitys.mine.address.AddressActivity
import com.help10000.rms.ui.activitys.mine.feedback.FeedBackListActivity
import com.help10000.rms.ui.activitys.mine.user_info.password.ChangePwdActivity
import com.help10000.rms.ui.utils.JsonUtils

object PushExtraHelper {


    fun handlePushIntent(input: Intent, out: Intent): Intent {
        var content = input.getStringExtra("push_content")
        out.putExtra("push_content", content)
        return out;
    }

    fun handlePush(context: Context, pushExtra: String) {
        var push = JsonUtils.getBean(pushExtra, PushDataEntity::class.java)
        if (push == null) {
            ToastUtil.show("通知处理出错")
            return
        }
        if (push.OpenUrl.isNullOrEmpty()) {
            ToastUtil.show("跳转地址为空")
            return
        }
        //未登录
        if (globalData.Cmpy == null) {
            var intent = Intent(context, LoginActivity::class.java)
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            context.startActivity(intent)
            return
        }
        when (push.OpenUrl) {
            "MY_ORDER_LIST" -> {
                var intent = Intent(context, OrderActivity::class.java)
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                context.startActivity(intent)
            }
            "MY_NEWORDER_LIST" -> {
                var intent = Intent(context, OrderActivity::class.java)
                intent.putExtra("type", OrderType.ROB_ORDER.ordinal)
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                context.startActivity(intent)
            }
            "MY_TIMEOUT_ORDER_LIST" -> {
                var intent = Intent(context, TimeOutOrderActivity::class.java)
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                context.startActivity(intent)
            }
            "MY_BANK" -> {
                var intent = Intent(context, MainActivity::class.java)
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                intent.putExtra("check_index", 1)
                context.startActivity(intent)
            }
            "MY_ADDR_LIST" -> {
                var intent = Intent(context, AddressActivity::class.java)
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                context.startActivity(intent)
            }
            "MY_FEELBACK_LIST" -> {
                var intent = Intent(context, FeedBackListActivity::class.java)
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                context.startActivity(intent)
            }
            "MY_PASSWORD_EDIT" -> {
                var intent = Intent(context, ChangePwdActivity::class.java)
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                context.startActivity(intent)
            }
        }

    }
}